package com.iot.mqtt;

public class SubPubResult {

    private Integer status;
    private String desc;
    private Exception e;

    public boolean isOk(){
        return this.status == 1;
    }

    public SubPubResult(Integer status) {
        this.status = status;
    }

    public SubPubResult(Integer status, String desc) {
        this.status = status;
        this.desc = desc;
    }

    public SubPubResult(Integer status, String desc, Exception e) {
        this.status = status;
        this.desc = desc;
        this.e = e;
    }

    public static SubPubResult result(Integer status){
        return new SubPubResult(status);
    }

    public static SubPubResult result(Integer status, String desc){
        return new SubPubResult(status, desc);
    }

    public static SubPubResult result(Integer status, String desc, Exception e){
        return new SubPubResult(status, desc, e);
    }

    public static SubPubResult ok(){
        return new SubPubResult(1);
    }

    public static SubPubResult fail(){
        return new SubPubResult(0);
    }

    public static SubPubResult fail(String desc){
        return new SubPubResult(0, desc);
    }

    public static SubPubResult fail(Exception e){
        return new SubPubResult(0, e.getLocalizedMessage(), e);
    }

    public static SubPubResult fail(String desc, Exception e){
        return new SubPubResult(0, desc, e);
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Exception getE() {
        return e;
    }

    public void setE(Exception e) {
        this.e = e;
    }
}
